#type vertex
#version 330 core
layout (location = 0) in vec3 aPos;

uniform mat4 _light_space_matrix;
uniform mat4 _model;

void main()
{
    gl_Position = _light_space_matrix * _model * vec4(aPos, 1.0);
}

#type fragment
#version 330 core

out vec4 FragOut;

vec4 pack (float depth) {
    // 使用rgba 4字节共32位来存储z值,1个字节精度为1/256
    const vec4 bitShift = vec4(1.0, 256.0, 256.0 * 256.0, 256.0 * 256.0 * 256.0);
    const vec4 bitMask = vec4(1.0/256.0, 1.0/256.0, 1.0/256.0, 0.0);
    // gl_FragCoord:片元的坐标,fract():返回数值的小数部分
    vec4 rgbaDepth = fract(depth * bitShift);//计算每个点的z值
    rgbaDepth -= rgbaDepth.gbaa * bitMask;// Cut off the value which do not fit in 8 bits
    return rgbaDepth;
}

void main()
{
    FragOut = vec4(gl_FragCoord.z, 0, 0, 1.0);
    //    FragOut = pack(gl_FragCoord.z);
}
